package com.ztf666.articlereview.controller;

import com.ztf666.articlereview.dto.R;
import com.ztf666.articlereview.entity.Review;
import com.ztf666.articlereview.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author z
 * @date 2022/2/21 下午1:05
 */
@RequestMapping("/review")
@RestController
public class ReviewController {
    private ReviewService reviewService;
    @Autowired
    public void setReviewService(ReviewService reviewService) {
        this.reviewService = reviewService;
    }
    @PostMapping("addReview")
    public R addReview(Integer UserId,Integer aid, Integer pid, String content){
        reviewService.addReview(UserId, aid,pid,content);
        return R.setOK();
    }
    @GetMapping("getReview")
    public R getReview(Integer aid){
       List<Review> reviews= reviewService.findReview(aid);
       return R.setOK(reviews);
    }

    @GetMapping("getSonReview")
    public R getSonReview(Integer aid,Integer pid){
        List<Review> reviews= reviewService.findReview(aid,pid);
        return R.setOK(reviews);
    }
}
